package com.dao;

import com.vo.Admin;
import com.vo.Student;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class AdminDao {


    private Connection conn=null;

    /**
     * 初始化数据库
     * @throws Exception
     */
    public void initConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        conn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/topiao?allowMultiQueries=true&useUnicode=true&useSSL=false","root","123456");
    }

    //登录
    public Admin adminLogin(String account, String pwd) throws Exception {
        Admin admin=null;
        initConnection();
        String sql="select * from t_admin where account=? and pwd=?";
        PreparedStatement ps=conn.prepareStatement(sql);
        ps.setString(1,account);
        ps.setString(2,pwd);
        ResultSet rs=ps.executeQuery();
        while (rs.next()){
            admin=new Admin();
            admin.setAccount(rs.getString("account"));
            admin.setPwd(rs.getString("pwd"));
        }
        closeConnection();
        return admin;
    }

    private void closeConnection() throws Exception{
        conn.close();
    }



}
